Introduction to Tornado by Michael Dory

Introduction to Tornado by Michael Dory

Author:Michael Dory
Language: eng
Format: epub, pdf
Publisher: O'Reilly Media
Published: 2012-03-21T00:00:00+00:00


def get(self, isbn=None): book = dict() if isbn: coll = self.application.db.books book = coll.find_one({"isbn": isbn}) self.render("book_edit.html", page_title="Burt's Books", header_text="Edit book", book=book)

If the method is invoked as a result of a request to /add, Tornado will call the get method without a second argument (as there’s no corresponding group in the regular expression for the path). In this case, the default, an empty book dictionary is passed to the book_edit.html template.

If the method was called as a result of a request to, for example, /edit/0-123-456, the isbn parameter is set to the value 0-123-456. In this case, we get the books collection from our Application instance and use it to look up the book with the corresponding ISBN. Then we pass the resulting book dictionary into the template.

Here’s the template (book_edit.html):



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.